package st.business.tepth.business.taskallocation.station;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.ModifyStationBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-07-17 17:46
 */

public class StationPresenter extends StationContract.Presenter {
    private final StationContract.View mView;
    private final StationContract.Model mModel;

    public StationPresenter(StationContract.View view) {
        mView = view;
        mModel = new StationModel();
    }

    @Override
    void getWorkPlace(String token, int repairId) {
        addDisposable(mModel.getWorkPlace(token, repairId,
                new OnDataConvertListener<ModifyStationBean>() {
                    @Override
                    public void convert(ModifyStationBean bean) {
                        if (mView != null) {
                            mView.showData(bean);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }

    @Override
    void modifyStation(String token, int repairId, int stationId) {
        addDisposable(mModel.modifyStation(token, repairId, stationId,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String str) {
                        if (mView != null) {
                            mView.modifySucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }
}
